<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <nav onclick="_onclick()">
        <a href="javascript:;">模块一</a>
        <a href="javascript:;">模块二</a>
        <a href="javascript:;">模块三</a>
        <a href="javascript:;">模块四</a>
    </nav>
    <div>模块一</div>
    <div>模块二</div>
    <div>模块三</div>
    <div>模块四</div>
</body>
</html>
<style>
    nav{
        position: sticky;
        top: 0;
        background-color: rgba(77, 77, 240, 0.699);
    }
    a{
        text-decoration:none;
        color: black;
        margin-left:15px;
    }
    div{
        height: 300px;
        margin-top:20px;
        line-height: 300px;
        border: 2px solid rgb(145, 145, 243);
    }
</style>
<script>
    let mDivs = document.getElementsByTagName('div');
    var nowWindowsHeight = window.innerHeight;
    //let navHeight = document.getElementsByTagName('nav')[0].style.height;
    window.onresize = function(){
        nowWindowsHeight = window.innerHeight;
    }
    function _onclick(){
        let nowClick = event.target.innerText;
        let j = 0;
        for (const i of mDivs) {
            j++
            if(nowClick == i.innerText){
                let nowHeight = i.getBoundingClientRect().top;
                //let nowBottom = i.getBoundingClientRect().bottom;
                methods(nowHeight, j);
                j = 0;
                break;
            }
            
        }
    }
    function methods(nowHeight, j){
        if(0 < nowHeight && nowHeight < 50){
            return
        } else {
            let a = (j - 1) * 300 + 25;
            window.scrollTo(0, a)
        }
    }
</script>